<template>
	<view class="template-message">
		<!-- 顶部自定义导航 -->
		<!-- <tn-nav-bar fixed :bottomShadow="false" backTitle=" ">
			<view class="">
				<text class="tn-text-lg">名片</text>
				<text class="tn-text-xl"></text>
			</view>
		</tn-nav-bar> -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>

		<view class="card" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="one">
				<view class="left">
					<image :src="info.tximg" mode=""></image>
				</view>
				<view class="right">
					<text>企业名称:&nbsp;&nbsp;{{info.qymc}}</text>
					<text>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:&nbsp;&nbsp;{{info.xm}}</text>
					<text>电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话:&nbsp;&nbsp;{{info.sjhm}}</text>
					<text>邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱:&nbsp;&nbsp;{{info.email}}</text>
					<text>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址:&nbsp;&nbsp;{{info.qydz}}</text>
				</view>
			</view>
			<view class="two">
				<view class="title" @click="showMore = !showMore">
					<text>展开全部名片信息</text>
				</view>
				<view class="list" v-if="showMore">
					<view class="item">
						<view class="label">手机号</view>
						<view class="value">{{info.sjhm}}</view>
					</view>
					<view class="item">
						<view class="label">姓名</view>
						<view class="value">{{info.xm}}</view>
					</view>
					<view class="item">
						<view class="label">企业名称</view>
						<view class="value">{{info.qymc}}</view>
					</view>
					<view class="item">
						<view class="label">地址</view>
						<view class="value">{{info.qydz}}</view>
					</view>
					<view class="item">
						<view class="label">职位</view>
						<view class="value">{{info.zhiwei}}</view>
					</view>
					<view class="item">
						<view class="label">微信号</view>
						<view class="value">{{info.wxh}}</view>
					</view>
					<view class="item">
						<view class="label">邮箱</view>
						<view class="value">{{info.email}}</view>
					</view>
					<view class="item">
						<view class="label">生日</view>
						<view class="value">{{info.sr}}</view>
					</view>
					<view class="item">
						<view class="label">性别</view>
						<view class="value">{{info.xb}}</view>
					</view>
					<view class="item">
						<view class="label">常住城市</view>
						<view class="value">{{info.czcs}}</view>
					</view>
					<view class="item">
						<view class="label">企业大类</view>
						<view class="value">{{info.qydlname}}</view>
					</view>
					<view class="item">
						<view class="label">企业小类</view>
						<view class="value">{{info.qyxlname}}</view>
					</view>
					<view class="item">
						<view class="label">业务介绍</view>
						<view class="value">{{info.ywjs}}</view>
					</view>
					<view class="item">
						<view class="label">企业介绍</view>
						<view class="value">{{info.qyjj}}</view>
					</view>
					<view class="item">
						<view class="label">点赞数</view>
						<view class="value">{{info.dianzancount}}</view>
					</view>
					<view class="item">
						<view class="label">浏览数</view>
						<view class="value">{{info.liulancount}}</view>
					</view>
					<view class="item">
						<view class="label">浏览者头像</view>
						<view class="value imgs" v-if="info.txList.length > 0">
							<image v-for="(item,index) in info.txList" :src="item" mode="widthFix" v-if="index <= 3">
							</image>
						</view>
					</view>
				</view>
			</view>
			<view class="three">
				<button open-type="share" @click="inOutCircle('2')" :data-id="id" data-type="mp">分享名片</button>
			</view>
			<view class="four" v-if="!id">
				<view class="item" @click="tn('/minePages/editInfo')">
					<view>编辑名片</view>
				</view>
				<view class="item" @click="tn('/circlePages/mykhList')">
					<view>我的客户</view>
				</view>
				<view class="item" @click="tn('/circlePages/gzkhList')">
					<view>关注客户</view>
				</view>
				<view class="item" @click="tn('/circlePages/qzkhList')">
					<view>浏览客户</view>
				</view>
			</view>
			<view class="four" v-if="id">
				<view class="item" v-if="info.iskh == '1'">
					<view @click="setKH(2)">移出客户</view>
				</view>
				<view class="item" v-else>
					<view @click="setKH(1)">设为客户</view>
				</view>
			</view>
			<view class="tn-flex tn-flex-row-between" style="padding: 30rpx 0 30rpx 0;" v-if="id">
				<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
					<tn-button backgroundColor="#00FFC6" padding="40rpx 0" width="90%" shadow fontBold
						@click="inOutCircle(info.isgz == '1'?'4':'3')">
						<text class="tn-icon-add tn-padding-right-xs tn-color-black"></text>
						<text class="tn-color-black">{{info.isgz == '1'?'取关':'关注'}}</text>
						<!-- <text class="tn-color-black">取关</text> -->
					</tn-button>
				</view>
				<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
					<tn-button backgroundColor="#FFF00D" padding="40rpx 0" width="90%" shadow fontBold
						@click="inOutCircle('1')">
						<text class="tn-icon-like tn-padding-right-xs tn-color-black"></text>
						<text class="tn-color-black">点赞</text>
					</tn-button>
				</view>
			</view>
			<view class="tn-flex tn-flex-direction-column tn-margin-top-sm tn-margin-bottom" v-if="content.length > 0">
				<!-- 图文信息 -->
				<block v-for="(item,index) in content">
					<view class="blogger__item" :key="index">
						<view class="blogger__author tn-flex tn-flex-row-between tn-flex-col-center">
							<view class="justify__author__info">
								<view class="tn-flex tn-flex-row-center">
									<view class="tn-flex tn-flex-row-center tn-flex-col-center">
										<view class="">
											<tn-avatar class="" shape="circle" :src="item.userAvatar" size="lg">
											</tn-avatar>
										</view>
										<view class="tn-padding-right tn-text-ellipsis">
											<view class="tn-padding-right tn-padding-left-sm tn-text-bold tn-text-lg">
												{{ item.userName }}
											</view>
											<view
												class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray">
												{{ item.date }}
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>

						<view
							class="blogger__desc tn-margin-top-sm tn-margin-bottom-sm tn-text-justify tn-flex-col-center tn-flex-row-left"
							@click="tn('/circlePages/details?iid='+item.iid)">
							<view v-for="(label_item,label_index) in item.label" :key="label_index"
								class="blogger__desc__label tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
								<text class="blogger__desc__label--prefix">#</text>
								<text class="tn-text-df">{{ label_item }}</text>
							</view>
							<!-- 不用限制长度了，因为发布的时候限制长度了-->
							<text v-if="!item.label || item.label.length < 4"
								class="blogger__desc__content tn-flex-1 tn-text-justify tn-text-df">{{ item.desc }}</text>
						</view>
						<block v-if="item.mainImage">
							<view v-if="[1,2,4].indexOf(item.mainImage.length) != -1" class="tn-padding-top-xs"
								@click="tn('/circlePages/details?iid='+item.iid)">
								<image v-for="(image_item,image_index) in item.mainImage" :key="image_index"
									class="blogger__main-image" :class="{
			        'blogger__main-image--1 tn-margin-bottom-sm': item.mainImage.length === 1,
			        'blogger__main-image--2 tn-margin-right-sm tn-margin-bottom-sm': item.mainImage.length === 2 || item.mainImage.length === 4
			      }" :src="image_item" mode="aspectFill"></image>
							</view>
							<view v-else class="tn-padding-top-xs" @click="tn('/circlePages/details?iid='+item.iid)">
								<tn-grid hoverClass="none" :col="3">
									<block v-for="(image_item,image_index) in item.mainImage" :key="image_index">
										<tn-grid-item style="width: 30%;margin: 10rpx;">
											<image class="blogger__main-image blogger__main-image--3" :src="image_item"
												mode="aspectFill"></image>
										</tn-grid-item>
									</block>
								</tn-grid>
							</view>
						</block>

						<!-- <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top-xs">
							<view class="justify-content-item tn-color-gray tn-text-center">
								<view class="">
									<text class="blogger__count-icon tn-icon-footprint"></text>
									<text class="tn-padding-right">{{ item.collectionCount }}</text>
									<text class="blogger__count-icon tn-icon-message"></text>
									<text class="tn-padding-right">{{ item.commentCount }}</text>
									<text class="blogger__count-icon tn-icon-like"
										@click.stop="dianzan(item)"></text>
									<text class="">{{ item.likeCount }}</text>
								</view>
							</view>
							<view class="justify-content-item tn-flex tn-flex-col-center">
								<view style="margin-right: 10rpx;margin-left: 20rpx;">
									<tn-avatar-group :lists="item.viewUser.latestUserAvatar"
										size="sm"></tn-avatar-group>
								</view>
								<text class="tn-color-gray">{{ item.viewUser.viewUserCount }}人</text>
							</view>
						</view> -->
						<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top-xs">
							<view class="justify-content-item tn-color-gray tn-text-center">
								<view style="margin-right: 10rpx;margin-left: 20rpx;">
									<tn-avatar-group :lists="item.viewUser.latestUserAvatar" size="sm"></tn-avatar-group>
								</view>
								<!-- <text class="tn-color-gray">{{ item.viewUser.viewUserCount }}人</text> -->
							</view>
							<view class="justify-content-item tn-flex tn-flex-col-center">
								<view class="justify-content-item tn-flex tn-flex-col-center">
									<button type="default" open-type="share" class="shareBtn" :data-id="item.iid"
										data-type="dongtai" @click.stop="">
										<text class="blogger__count-icon tn-icon-share"></text>
									</button>
									<!-- <text class="tn-padding-right">{{ item.collectionCount }}</text> -->
									<text class="blogger__count-icon tn-icon-message"></text>
									<text class="tn-padding-right">{{ item.commentCount }}</text>
									<text class="blogger__count-icon tn-icon-like" @click.stop="dianzan(item)"></text>
									<text class="">{{ item.likeCount }}</text>
									<!-- <button type="default" open-type="share" class="shareBtn" :data-id="item.iid"
										data-type="dongtai" @click.stop="">
										<text class="blogger__count-icon tn-icon-share"></text>
									</button> -->
								</view>
							</view>
						</view>
					</view>

					<!-- 边距间隔 -->
					<view class="tn-strip-bottom" v-if="index != content.length - 1"></view>
				</block>

				<!-- 边距间隔 -->
				<view class="tn-strip-bottom"></view>
			</view>
		</view>
	</view>

</template>

<script>
	import Tools from '@/tools/config.js'
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'card',
		mixins: [template_page_mixin],
		data() {
			return {
				info: {
					qymc:"",
					xm:"",
					sjhm:"",
					email:"",
					qydz:"",
				},
				showMore: false,
				id: "",
				content:[],
			}
		},
		onLoad(options) {
			this.id = options.id || ""
		},
		onShow(){
			this.getislogin('openid').then(()=>{
				this.initData()
				this.getDongtai()
			})
		},
		methods: {
			getDongtai(){
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'dongtai_mpiid',
						'openid': theopenid,
						'unionid': theunionid,
						'mpiid': this.id,
						'pagesize': 20,
						'pageindex': this.pages
					},
					success: (res) => {
						//成功
						if (res.data.return_code == 1) {
							var thejson = JSON.parse(res.data.data)
							console.log('res1：' + thejson, res.data.data)
							// this.bloggerList = thejson
							this.content = this.content.concat(thejson)
						}
					},
					fail: (res) => {
						console.log('失败' + res)
					}
				});
			},
			tn(url) {
				uni.navigateTo({
					url: url
				})
			},
			setKH(type) {
				// 1设为客户2移出客户
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'mpxx_szkh',
						'openid': theopenid,
						'unionid': theunionid,
						'mpiid': this.id,
						'szkhlx': type
					},
					success: (res) => {
						//成功
						if (res.data.return_code == 1) {
							uni.showToast({
								title: type == 1 ? '已设为客户' : "已移出客户",
								icon: "success"
							})
						}else{
							uni.showToast({
								title:"设置失败",
								icon:"none"
							})
						}
						this.initData()
					},
					fail: (res) => {
						console.log('失败' + res)
					}
				});
			},
			inOutCircle(type) {
				//1点赞，2分享,3关注
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'mp_dzfxgz',
						'openid': theopenid,
						'unionid': theunionid,
						'mpiid': this.id,
						'type': type
					},
					success: (res) => {
						//成功
						if (res.data.return_code == 1) {
							uni.showToast({
								title: type == 1 ? '点赞成功' : type == 3 ? "已关注" : type == 4 ? "已取关" : "",
								icon: "success"
							})
							this.initData()
						}
					},
					fail: (res) => {
						console.log('失败' + res)
					}
				});
			},
			initData() {
				let that = this
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'mpxx_xg_s',
						'openid': theopenid,
						'unionid': theunionid,
						'mpiid': this.id,
					},
					success: (res) => {
						//成功
						if (res.data.return_code == 1) {
							var thejson = JSON.parse(res.data.data)
							if (thejson.liulantximg) {
								thejson.txList = thejson.liulantximg.split(",")
							}
							that.info = thejson
							console.log(that.info)
						}
					},
					fail: (res) => {
						console.log('失败' + res)
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.shareBtn{
		display:inline-flex;
		background-color: unset;
		line-height: unset;
	}
	.shareBtn::before{
		all:unset;
	}
	.shareBtn::after{
		all:unset;
	}
	
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;
	
		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}
	
		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}
	.card {
		.one {
			margin: 24rpx;
			padding: 24rpx;
			border-radius: 24rpx;
			background-color: #FFFFFF;
			display: flex;
			flex-direction: row;

			.left {
				width: 200rpx;
				height: 200rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 24rpx;
				}
			}

			.right {
				flex: 1;
				margin-left: 16rpx;
				display: flex;
				flex-direction: column;
				justify-content: flex-start;

				text {
					line-height: 40rpx;
				}
			}
		}

		.two {
			margin: 0 24rpx 24rpx;
			padding: 0 40rpx;
			display: flex;
			flex-direction: column;

			.title {
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				text {
					font-size: 24rpx;
					color: #999;
				}
			}

			.list {
				display: flex;
				flex-direction: column;

				.item {
					display: flex;
					flex-direction: row;
					min-height: 72rpx;
					align-items: center;

					.label {
						width: 200rpx;
					}

					.value {
						flex: 1;
					}

					.imgs {
						display: flex;
						flex-direction: row;

						image {
							width: 30rpx;
							border-radius: 100%;
						}
					}
				}
			}
		}

		.three {
			margin-top: 24rpx;
			padding: 0 24rpx;

			button {
				border-radius: 40rpx;
				background-color: cadetblue;
				color: white;
			}
		}

		.four {
			margin-top: 24rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			padding: 0 24rpx;

			.item {
				flex: 1;
				margin: 0 10rpx;

				view {
					border-radius: 40rpx;
					background-color: aquamarine;
					display:flex;
					align-items: center;
					justify-content: center;
					padding: 24rpx 0;
				}
			}
		}
	}
	.blogger {
		&__item {
			padding: 30rpx;
		}
	
		&__author {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}
	
		&__desc {
			line-height: 55rpx;
	
			&__label {
				padding: 0 20rpx;
				margin: 0rpx 18rpx 0 0;
	
				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}
	
			&__content {}
		}
	
		&__content {
			margin-top: 18rpx;
			padding-right: 18rpx;
	
			&__data {
				line-height: 46rpx;
				text-align: justify;
				overflow: hidden;
				transition: all 0.25s ease-in-out;
	
			}
	
			&__status {
				margin-top: 10rpx;
				font-size: 26rpx;
				color: #82B2FF;
			}
		}
	
		&__main-image {
			border-radius: 16rpx;
	
			&--1 {
				max-width: 80%;
				max-height: 300rpx;
			}
	
			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}
	
			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}
	
		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}
	
		&__ad {
			width: 100%;
			height: 500rpx;
			transform: translate3d(0px, 0px, 0px) !important;
	
			::v-deep .uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}
	
			.uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}
	
			&__item {
				position: absolute;
				width: 100%;
				height: 100%;
				transform-origin: left center;
				transform: translate3d(100%, 0px, 0px) scale(1) !important;
				transition: transform 0.25s ease-in-out;
				z-index: 1;
	
				&--0 {
					transform: translate3d(0%, 0px, 0px) scale(1) !important;
					z-index: 4;
				}
	
				&--1 {
					transform: translate3d(13%, 0px, 0px) scale(0.9) !important;
					z-index: 3;
				}
	
				&--2 {
					transform: translate3d(26%, 0px, 0px) scale(0.8) !important;
					z-index: 2;
				}
			}
	
			&__content {
				border-radius: 40rpx;
				width: 640rpx;
				height: 500rpx;
				overflow: hidden;
			}
	
			&__image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>